import dva from 'dva';
import {fetch} from '../services/fetch'

export default {
  namespace: 'photos',
  state: {
    list:[],
    total:0
  },
  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
        if (location.pathname === '/') {
          fetch("/api/_search?key=cat&page=0")
            .then(function(res){return res.json()})
            .then(function(data){
              // self.setState({
              //   recommend_user_list: data.data,
              //   recommend_user_loading: false,
              // });
              dispatch({
                type: 'search',
                payload: data
              });
              console.log(data);
            });

        }
      });
    },
  },
  reducers: {
    search(state,action) {
      console.log(22222)
      return { ...state,
        total:action.payload.total,
        list:action.payload.hits
      };
    },
  },
};
